<template>
  <div class="file-wrap">
    <img
      style="width: 20px; height: 20px"
      :src="fileIcon[fileInfo.name.split('.')[1]]"
    />
    <el-tag
      class="tag-file"
      :closable="closable"
      type="info"
      @close="deleteFile(fileInfo)"
    >
      <a
        class="file-text"
        :href="fileInfo.url"
        target="_blank"
        @click="clickFile(fileInfo)"
      >
        {{ fileInfo.name }}</a
      >
    </el-tag>
  </div>
</template>

<script>
export default {
  props: {
    fileInfo: {
      type: Object,
    },
    closable: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      fileIcon: {
        xls: require('@/assets/images/file_icon/icon_excel.png'),
        xlsx: require('@/assets/images/file_icon/icon_excel.png'),
        doc: require('@/assets/images/file_icon/icon_word.png'),
        docx: require('@/assets/images/file_icon/icon_word.png'),
        pdf: require('@/assets/images/file_icon/icon_pdf.png'),
        jpg: require('@/assets/images/file_icon/icon_image.png'),
        jpeg: require('@/assets/images/file_icon/icon_image.png'),
        ppt: require('@/assets/images/file_icon/icon_pw.png'),
        pptx: require('@/assets/images/file_icon/icon_pw.png'),
      },
    }
  },
  methods: {
    deleteFile(fileInfo) {
      this.$emit('delete', fileInfo)
    },
    clickFile(fileInfo) {
      this.$emit('click', fileInfo)
    },
  },
}
</script>

<style lang="less" scoped>
.file-wrap {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  color: #909399;
  border: 1px solid #e9e9eb;
  background-color: #f4f4f5;
  border-radius: 4px;
  margin-left: 10px;
  padding-left: 4px;
  margin-bottom: 4px;
}
.el-tag {
  border-width: 0px !important;
}
.tag-file {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-text:hover {
  color: #1890ff;
  // font-weight: bold;
  border-bottom: 1px solid #1890ff;
}
</style>
